package com.admin.business.workManagement.venusOaWorkPunishment;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 工作惩罚设置
 * @create: 2023-11-14 15:21:41
 **/
@Service("venusOaWorkPunishmentService")
@Slf4j
public class VenusOaWorkPunishmentService{

    @Resource
    VenusOaWorkPunishmentDao venusOaWorkPunishmentDao;

    /**
     * 添加工作惩罚设置,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - user_id:添加人
     *                   - unfinished_work:未完成安排扣除工资
     *                   - vertime_to_complete_work:超时完成成安排扣除工资
     *                   - refused_to_work:拒绝安排扣除工资
     *                   - cancel_the_task:取消任务扣除工资
     *                   - reassigning_tasks:改派任务扣除工资
     *                   - unfinished_cycle_plan:未完成循环计划扣除工资
     *                   - false_completion_cycle_plan:虚假完成循环计划扣除工资
     *                   - update_id:修改人
     *                   - begin_time:创建时间
     *                   - state:状态 0 正常 1 删除
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return addVenusOaWorkPunishment(CDO cdoRequest) {
        venusOaWorkPunishmentDao.addVenusOaWorkPunishment(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新工作惩罚设置数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - user_id:添加人
     *                   - unfinished_work:未完成安排扣除工资
     *                   - vertime_to_complete_work:超时完成成安排扣除工资
     *                   - refused_to_work:拒绝安排扣除工资
     *                   - cancel_the_task:取消任务扣除工资
     *                   - reassigning_tasks:改派任务扣除工资
     *                   - unfinished_cycle_plan:未完成循环计划扣除工资
     *                   - false_completion_cycle_plan:虚假完成循环计划扣除工资
     *                   - update_id:修改人
     *                   - begin_time:创建时间
     *                   - state:状态 0 正常 1 删除
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return updateVenusOaWorkPunishmentById(CDO cdoRequest) {
        venusOaWorkPunishmentDao.updateVenusOaWorkPunishmentById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除工作惩罚设置数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return deleteVenusOaWorkPunishmentById(CDO cdoRequest){
        int count = venusOaWorkPunishmentDao.deleteVenusOaWorkPunishmentById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除工作惩罚设置数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return deleteVenusOaWorkPunishment(CDO cdoRequest) {
        int count = venusOaWorkPunishmentDao.deleteVenusOaWorkPunishment(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取工作惩罚设置数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return getVenusOaWorkPunishmentById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaWorkPunishmentDao.getVenusOaWorkPunishmentById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取工作惩罚设置数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return getVenusOaWorkPunishmentListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkPunishmentDao.getVenusOaWorkPunishmentListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkPunishmentDao.getVenusOaWorkPunishmentCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取工作惩罚设置数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:41
     */
    @OpenApi
    public Return getVenusOaWorkPunishmentListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkPunishmentDao.getVenusOaWorkPunishmentListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkPunishmentDao.getVenusOaWorkPunishmentCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
